<template>
	<view class="content">
		<view class="withdrawal flex">
			<view>
				<view class="keyTitle">
					<view>提现金额</view>
				</view>
				<view>
					  <u--input
					    placeholder="请输入金额"
					    border="bottom"
						v-model="money"
					    clearable
					  ></u--input>
				</view>
			</view>
			<view>
				<view class="keyTitle">收款二维码</view>
				<view>
					<u-upload
						:fileList="fileList1"
						@afterRead="afterRead"
						@delete="deletePic"
						name="1"
						:maxCount="10"
					>
						</u-upload>
				</view>
			</view>
			<view>
				<view class="keyTitle">提现到</view>
				<view>
					  <u-radio-group
					    v-model="source"
					    placement="column"
			
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(item, index) in radiolist1"
					      :key="index"
					      :label="item.name"
					      :name="item.id"
					    >
					    </u-radio>
					  </u-radio-group>
				</view>
			</view>
			<view class="ticp">
				<view>平台收取1%提现手续费 线下转账</view>
				<view>可提现金额: {{userMoney}}元</view>
			</view>
		</view>

		<view class="goWithdrawal" @click="goWithdrawal">
			立即提现
		</view>
	</view>
</template>

<script>
		import baseInfo from '@/config/base.js';
		import http from '@/apis/http.js'
	export default {
		data() {
			return {
				money:'',
				userMoney:0,
				fileList1:[],
				source:1,
				radiolist1:[
					{'name':'微信',id:1},
					{'name':'支付宝',id:2},
				]
			}
		},
		methods: {
			getUserMoney()
			{
				http.POST('user_vip/userMoney').then(res=>{
					this.userMoney = res.data
				})
			},
			// 删除图片
						deletePic(event) {
							this[`fileList${event.name}`].splice(event.index, 1)
						},
						// 新增图片
						async afterRead(event) {
							// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
							let lists = [].concat(event.file)
							let fileListLen = this[`fileList${event.name}`].length
							lists.map((item) => {
								this[`fileList${event.name}`].push({
									...item,
									status: 'uploading',
									message: '上传中'
								})
							})
							for (let i = 0; i < lists.length; i++) {
								const result = await this.uploadFilePromise(lists[i].url)
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						},
						
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: baseInfo.baseUrl+'index.php/api/tourism_life/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							res = JSON.parse(res.data)
							setTimeout(() => {
								resolve(res.data.url)
							}, 1000)
						}
					});
				})
			},
			goWithdrawal(){
				let images = '';
				for(var i in this.fileList1){
					images += this.fileList1[i].url + ',';
				}

				http.POST('user_vip/withdrawal',{
					'qrcode':images,
					'money' : this.money,
					'source':this.source
				}).then(res=>{
					if(res.code == 1){
						uni.showToast({
							'title':'操作成功',
							'icon':'none'
						})
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/my/wallet'
							})
						},1000)
					}else{
						uni.showToast({
							'title':res.msg,
							'icon':'none'
						})
					}
				})
				
			}
		},
		created() {
			this.getUserMoney()
		}
	}
</script>

<style>
	.flex{display: flex;}
	.content { padding: 20rpx; background-color: #ffffff; height: 100%;}
	.withdrawal{
		 box-shadow: 0 0 4rpx 3rpx #eeeeee;  border:1px solid #eeeeee; 
		flex-direction: column; border-radius: 20rpx; background: #fff; padding: 10rpx 20rpx 20rpx 20rpx;}
	.keyTitle { margin-top: 50rpx; margin-bottom: 20rpx;}
	.ticp { margin: 20rpx 0; color: darkgrey;}
	.goWithdrawal {text-align: center;  margin: 80rpx 0 0 40rpx; color:#fff; height: 70rpx; line-height: 70rpx; width: 90%;  border-radius: 50rpx; background-color: red;}
	
</style>
